<?php namespace My\Field\Quan;

class Jiagefanwei extends \Phpcmf\Library\A_Field {
	
	/**
     * 构造函数
     */
    public function __construct() {
        parent::__construct();
		$this->fieldtype = ['TEXT' => '']; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
		$this->defaulttype = 'TEXT'; // 当用户没有选择字段类型时的缺省值
    }
	
	/**
	 * 字段相关属性参数
	 *
	 * @param	array	$value	值
	 * @return  string
	 */
	public function option($option) {

		return [''];
	}

    /**
     * 创建sql语句
     */
	/*public function create_sql($name, $value, $cname = '') {
	    $sql = 'ALTER TABLE `{tablename}` ADD `'.$name.'` TEXT NULL , ADD `'.$cname.'` TEXT NULL';
	    return $sql;
	}*/

    /**
     * 修改sql语句
     */
    public function alter_sql($name, $value, $cname = '') {
        return NULL;
    }

    /**
     * 删除sql语句
     */
    public function drop_sql($name) {
        return 'ALTER TABLE `{tablename}` DROP `'.$name.'`';
    }
	
	/**
	 * 字段输出
	 */
	public function output($value) {
		return $value;
	}
	
	/**
	 * 字段入库值
	 */
	public function insert_value($field) {
		$zus = \Phpcmf\Service::L('field')->post[$field['fieldname']];
		if($zus) {
			$zu = [
			'dijia' => $zus['dijia'],
			'gaojia' => $zus['gaojia'],
			'danwei' => $zus['danwei'],
			];
			
			\Phpcmf\Service::L('field')->data[$field['ismain']][$field['fieldname']] = dr_array2string($zu);
		}
		

	}

    /**
     * 字段表单输入
     *
     * @return  string
     */
    public function input($field, $value = []) {

        // 字段禁止修改时就返回显示字符串
        /*if ($this->_not_edit($field, $value)) {
            return $this->show($field, $value);
        }*/

        // 字段存储名称
        $name = $field['fieldname'];

        // 字段显示名称
        $text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').$field['name'];

        // 表单附加参数
        $attr = $field['setting']['validate']['formattr'];

        // 字段提示信息
        $tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';

        // 是否必填
        $required =  $field['setting']['validate']['required'] ? ' required="required"' : '';



        // 字段默认值
        $value = dr_string2array(\Phpcmf\Service::L('Field')->value[$field['fieldname']]);
	

        // 表单选项
        //$str = '<label><select '.$required.' class="form-control '.$field['setting']['option']['css'].'" name="data['.$name.']" id="dr_'.$name.'_ting" '.$attr.' >';
        //$str.= '<option value="0">'.dr_lang('选择分类').'</option>';
        //$options = \Phpcmf\Service::M('content', 'www')->son_type(\Phpcmf\Service::C()->index['son_type']);
		$wo = \Phpcmf\Service::C()->index['uid'];
		$uid = \Phpcmf\Service::C()->uid;

		$strs.= '
		<label>
			<input type="text" style="width: 90px;" class="form-control" autocomplete="off" placeholder="最低薪资" name="data['.$name.'][dijia]" value="'.$value['dijia'].'">
		</label>
		<label>
			<input type="text" style="width: 90px;" class="form-control" autocomplete="off" placeholder="最高薪资" name="data['.$name.'][gaojia]" value="'.$value['gaojia'].'">
		</label>
		<label>
			<select '.$required.' class="form-control '.$field['setting']['option']['css'].'" name="data['.$name.'][danwei]" id="dr_'.$name.'_danwei" '.$attr.' >

				<option value="1" '.(1 == $value['danwei'] ? ' selected' : '').'>月</option>
				<option value="2" '.(2 == $value['danwei'] ? ' selected' : '').'>天</option>
				<option value="3" '.(3 == $value['danwei'] ? ' selected' : '').'>小时</option>

			</select>
		</label>

		';

        $str.= $strs;
        return $this->input_format($name, $text, $str);
    }



    /**
     * 字段表单显示
     *
     * @param	string	$field	字段数组
     * @param	array	$value	值
     * @return  string
     */
    public function show($field, $value = null) {

        $options = dr_format_option_array($field['setting']['option']['options']);

        $str = '<div class="form-control-static"> '.(isset($options[$value]) ? $options[$value] : dr_lang('未选择')).' </div>';

        return $this->input_format($field['fieldname'], $field['name'], $str);
    }
}